
#ifndef VDEC_ENGINE_H
#define VDEC_ENGINE_H
#include <vector>
#include "dvpp/Vpc.h"
#include "dvpp/dvpp_config.h"
#include "dvpp/idvppapi.h"
#include "dvpp/Vdec.h"
#include "hiaiengine/api.h"
#include "hiaiengine/engine.h"
#include "hiaiengine/multitype_queue.h"
#include "hiaiengine/ai_model_manager.h"
#include "trans_data.h"
using namespace hiai;
#define INPUT_SIZE 1
#define OUTPUT_SIZE 1

class DecodeH26xInfo : public HIAI_DATA_SP {
public:
    void* vdecEnginePtr;
    uint64_t frameId;
    uint32_t resizeWidth;
    uint32_t resizeHeight;
    ~DecodeH26xInfo()
    {}
};

typedef struct {
    uint64_t frameId;
    uint32_t width;
    uint32_t height;
    uint32_t alignWidth;
    uint32_t alignHeight;
    shared_ptr<uint8_t> buf;
    uint32_t len;
    float decodeFps;
} FRAME_BUFFER;

class VdecEngine : public Engine {
public:
    VdecEngine() : input_que_(INPUT_SIZE){};
    ~VdecEngine();
    static void VdecResultCallback(FRAME*, void*);
    static void VdecErrorCallback(VDECERR* vdecErr);
    HIAI_StatusT Init(const AIConfig&, const std::vector<AIModelDescription>&);
    HIAI_StatusT DecodeH26xVideo(std::shared_ptr<TransData> streamRawData);
    HIAI_StatusT VdecImageResize(FRAME* frame, std::shared_ptr<FRAME_BUFFER> buff, int w, int h);
    HIAI_StatusT GetOutputSize(int& width, int& height, int format);
    HIAI_StatusT TransferData(std::shared_ptr<FRAME_BUFFER> frameTemp, std::shared_ptr<TransData> config);
    uint64_t GetCurentTimeStamp();
    HIAI_DEFINE_PROCESS(INPUT_SIZE, OUTPUT_SIZE);
    static uint64_t decodeFrameNum;

private:
    // common parameters
    hiai::MultiTypeQueue input_que_;
    /* define DVPP object */
    IDVPPAPI* piDvppApiVdec = NULL;
    IDVPPAPI* piDvppApiVpc = NULL;
    /* transfer data between the callback functiong and main process */
    queue<std::shared_ptr<FRAME_BUFFER>> frameQueue;
    uint64_t initTimeStamp = 0;
    int eos = 0;
};

#endif